package reflect;

import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Test3 {
    public static void main(String[] args) throws Exception{
        File dir = new File(
                Test3.class.getResource(".").toURI()
        );
        String packname = Test3.class.getPackage().getName();
        File[] subs = dir.listFiles(f->f.getName().endsWith(".class"));
        for(File sub : subs){
            String fileName = sub.getName();
            //根据文件名截取出类名
            String className = fileName.substring(0,fileName.indexOf("."));;
            Class cls = Class.forName(packname+"."+className);//"reflect.Person"
            Object o = cls.newInstance();
            Method[] methods = cls.getMethods();
            for (Method method : methods) {
                if (method.getParameterCount()==0&method.getModifiers()== Modifier.PUBLIC&method.getName().contains("s")){
                          method.invoke(o);
                }
            }
        }
    }

}
